from web import models
from django import  forms
class BaseForm(object):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        for name,item in self.fields.items():
            item.widget.attrs['class']='form-control'
            item.widget.attrs['placeholder']=f'请输入{item.label}'
        # print(self.fields['parent'].queryset)
class WikiForm(BaseForm,forms.ModelForm):
    #parent=forms.ModelChoiceField(widget=forms.ChoiceField(),queryset=models.Wiki.objects.filter(project=self.request.tracer.project))
    class Meta:
        model=models.Wiki
        fields = ['id','title','content','parent']
        # exclude = ['project',]

    def __init__(self,request,*args,**kwargs):
        super().__init__(*args,**kwargs)
        self.request=request
        total_list=[('','---'),]
        dataSet=models.Wiki.objects.filter(project=self.request.tracer.project).values_list('id','title')
        total_list.extend(dataSet)
        self.fields['parent'].choices =total_list